package com.rao.travel.dao;

import com.rao.travel.pojo.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Srao
 * @version 1.0
 * @className PermissionDao
 * @date 2019/11/1 12:51
 * @package com.rao.travel.dao
 * @description
 */
@Mapper
public interface PermissionDao {
    /*根据角色id查询角色的权限*/
    @Select("select * from permission where id in (select permissionId from role_permission where roleId = #{id})")
    List<Permission> findByRoleId(String id);

    /*查询所有权限*/
    @Select("select * from permission")
    List<Permission> findAll();

    /*保存权限*/
    @Insert("insert into permission(permissionName, url) values (#{permissionName}, #{url})")
    void save(Permission permission);

    /*查看权限详情*/
    @Select("select * from permission where id = #{id}")
    Permission findById(String id);

    /*删除role_permission中的权限*/
    @Delete("delete from role_permission where permissionId = #{id}")
    void deleteFromRolePermission(String id);

    /*删除permission中的权限*/
    @Delete("delete from permission where id = #{id}")
    void deleteFromPermission(String id);
}
